import 'dart:math';

import 'package:fancy_shimmer_image/fancy_shimmer_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:qianyi/entity/home/AlbumEntity.dart';
import 'package:qianyi/entity/home/album_detail_list_entity.dart';
import 'package:qianyi/entity/message/inner/FollowEntity.dart';
import 'package:qianyi/entity/message/inner/LikeAndCollectEntity.dart';
import 'package:qianyi/network/http_manager.dart';
import 'package:qianyi/view_model/home/trend_view_model.dart';

import '../../../../controller/homeTabController.dart';
import '../../../../controller/imageDetailUserController.dart';
import '../../../../controller/imageDetailVideoController.dart';
import '../../../../entity/mine/User.dart';
import '../../../../entity/tags/Item.dart';
import '../../../../network/http_config.dart';
import '../../../../network/http_entity.dart';
import '../../../../state/token.dart';
import '../../../../ui/widget/custom_refresh.dart';
import '../../../../utils/throttle.dart';
import '../../../../view_model/home/AlbumDetailListModel.dart';
import '../../../../view_model/home/tags/TagsDetailListModel.dart';
import '../../../../view_model/message/inner/follow_view_model.dart';
import '../../../../view_model/message/inner/like_and_collect_view_model.dart';
import '../../../../view_model/mine/album_view_model.dart';
import '../../../../wcao/ui/theme.dart';


class FollowScreen extends StatefulWidget {
  @override
  _LikeAndCollectScreenState createState() => _LikeAndCollectScreenState();
}

class _LikeAndCollectScreenState extends State<FollowScreen> {
  HomeTabController homeTabController = Get.find();
  CategoryItem? albumEntity;
  ImageDetailUserController imageDetailUserController = Get.find();

  bool isFinish = false;
  List<String> images = [
    'https://example.com/image1.jpg', // 替换为实际图片链接
    'https://example.com/image2.jpg', // 替换为实际图片链接
    // 添加更多图片链接...
  ];
  List<String> tabs = ["最新","最热"];
  @override
  void initState() {

    // TODO: implement initState
    super.initState();
    // getAlbumEntity();
  }
  getAlbumEntity() async {
    HudUtil.showBeautiful(context);
    Map<String,String> params1 = {
      "id":homeTabController.tagDetailId!,
    };

    HttpEntity httpEntity1 = await HttpManager.getInstance().request(url: '/platform/tag/getOneTag/',params: params1,method: Method.get) as HttpEntity;
    setState(() {
      albumEntity = CategoryItem.fromJson(httpEntity1.getOriData()['data']);
      this.isFinish = true;
    });
    HudUtil.dismiss();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("关注记录")

      ),
      body: SafeArea(child: ChangeNotifierProvider(
        create: (context) => FollowViewModel(),
        child: Consumer<FollowViewModel>(
            builder: (context, viewModel, child) {

              return

                CustomRefresh(

                    isMaterialHeader:true,
                    controller: viewModel.refreshController,
                    enablePullUp: true,
                    enablePullDown: true,
                    onRefresh: () async {
                      viewModel.onRefresh();
                    },
                    onLoading: () async {
                      viewModel.onLoading();
                    },
                    child: ListView.builder(
                      itemCount: viewModel.datas.length,
                      itemBuilder: (BuildContext context, int index) {
                        FollowItem item = viewModel.datas[index];
                        return GestureDetector(
                            onTap: () async {
                              HudUtil.showBeautiful(context);
                              if(imageDetailUserController.user.length > 0) {
                                imageDetailUserController.user.clear();

                              }

                              Map<String,dynamic> param = {
                                "uid": item.uid
                              };
                              HttpEntity httpEntity = await HttpManager.getInstance().request(url: '/platform/user/getUserInfo',method: Method.get,params: param) as HttpEntity;
                              User user = User.fromJson(httpEntity.getOriData()['data']);
                              imageDetailUserController.user.add(user);
                              imageDetailUserController.userId = item.uid!;
                              HudUtil.dismiss();
                              Get.toNamed("/user/otherUserScreen");
                            },
                            child: Card(
                              margin: EdgeInsets.all(8.0),
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [

                                  Row(
                                    children: [
                                      ClipOval(
                                          child: FancyShimmerImage(imageUrl: '${item.avatar}',width: 40,height: 40,)
                                      )
                                      ,

                                      Column(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          Container(

                                              child: Text('${item.username}',style: TextStyle(

                                              ),)
                                          )
                                          ,
                                          Row(
                                            children: [
                                              Text("期待的关注了你"),

                                            ],
                                          ),
                                          Row(
                                            children: [
                                              Text("${DateFormat.Md().format(
                                                  DateTime.fromMillisecondsSinceEpoch(item.time!)
                                              )}-"),
                                              Text("${DateFormat.Hms().format(
                                                  DateTime.fromMillisecondsSinceEpoch(item.time!)
                                              )}")
                                            ],
                                          )

                                        ],
                                      )
                                    ],
                                  ),
                                  Flexible(child: Text('${item.username}',maxLines: 3,))
                                  ,
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                                    children: [

                                      // FancyShimmerImage(imageUrl: '${item.cover}',height: 80,width:65,boxFit: BoxFit.cover,)
                                    ],
                                  )

                                ],
                              ),
                            )
                        )
                        ;
                      },
                    )
                );
            }),
      )),
    );
    ;
  }


}
class CategoryItem {
  String id;
  String? creator;
  String? createDate;
  String count;
  String name;
  String? sort;

  CategoryItem({
    required this.id,
    this.creator,
    this.createDate,
    required this.count,
    required this.name,
    this.sort,
  });

  factory CategoryItem.fromJson(Map<String, dynamic> json) {
    return CategoryItem(
      id: json['id'],
      creator: json['creator'],
      createDate: json['createDate'],
      count: json['count'],
      name: json['name'],
      sort: json['sort'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'creator': creator,
      'createDate': createDate,
      'count': count,
      'name': name,
      'sort': sort,
    };
  }
}
